package com.gec.teams.wechat.mapper;

import com.gec.teams.wechat.pojo.Dto.UserLoginDto;
import com.gec.teams.wechat.pojo.TbDept;
import com.gec.teams.wechat.pojo.TbUser;
import com.gec.teams.wechat.pojo.vo.TbUserVo;
import com.gec.teams.wechat.pojo.vo.UserDeptVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
* @author Admin
* @description 针对表【tb_user(用户表)】的数据库操作Mapper
* @createDate 2024-06-12 22:40:29
* @Entity com.gec.teams.wechat.pojo.TbUser
*/
@Repository
public interface TbUserMapper {



    @Select("select IF(COUNT(*),TRUE,FALSE) from tb_user where root=1")
    @ResultType(Boolean.class)
    boolean haveRootUser();

    int insertInt(TbUserVo userVo);
    int deleteByPrimaryKey(Long id);

    int insert(TbUser record);

    int insertSelective(TbUser record);

    TbUser selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TbUser record);

    int updateByPrimaryKey(TbUser record);

    public ArrayList<HashMap> searchUserGroupByDept(String keyword);

    Set<String> getsearchUserPermissions(int id);

    @Select("select id,status from  tb_user where open_id=#{openId}")
    UserLoginDto getIdByOpenId(String openId);

    @Select("select  IF(COUNT(*),TRUE,FALSE) from tb_user where open_id=#{openId}")
    boolean haveOpenId(String openId);

    @Select("select * from tb_user where id=#{userId}")
    @Results({
            @Result(id=true,property="id",column="id"),
            @Result(property="openId",column="open_id"),
            @Result(property="nickname" ,column="nickname"),
            @Result(property="photo",column="photo" ),
            @Result(property="name" ,column="name" ),
            @Result(property="sex" ,column="sex" ),
            @Result( property="tel" ,column="tel" ),
            @Result( property="email" ,column="email" ),
            @Result( property="hiredate" ,column="hiredate"),
            @Result( property="role" ,column="role" ),
            @Result( property="root" ,column="root"),
            @Result( property="status" ,column="status" ),
            @Result( property="createTime", column="create_time" ),
            @Result(property = "dept",column = "dept_id",
            javaType = TbDept.class,
            one=@One(select = "com.gec.teams.wechat.mapper.TbDeptMapper.selectByPrimaryKey"))
    })
    UserDeptVo getUserAndDept(Integer userId);

    @Select(" SELECT hiredate FROM tb_user WHERE id=#{userId} AND status=1")
    String searchUserHiredate(Integer userId);

    public ArrayList<HashMap> searchMembers(List param);

//    @Select("select * from tb_user u,tb_dept d where status=1 ")
//    ArrayList<HashMap> searchUserGroupByDept(String keyword);
}
